app.controller("order", ["$scope", "$rootScope", "$timeout", "$state", "$http", function($scope, $rootScope, $timeout, $state, $http) {
		$rootScope.page.showfooter = true;
		$rootScope.page.footer = 'mine';
		$rootScope.findshopcarNum()
		scrollTo(0, 0);
		$rootScope.page.goshow = true
			//售后部分js
		$scope.page.show = true;
		$scope.page.hide = false;
		$scope.allOrder = function() {
			$state.go("main.myOrder")
		}
		$scope.waitCom = function() {
			$state.go("main.wait_comment")
		}
		$scope.afterSer = function() {
			$state.go("main.after_sales")
		}
		$scope.waitCom = function() {
			$state.go("main.wait_comment")
		}
		$scope.pageshow = function() {
			$scope.page.show = true;
			$scope.page.hide = false;
		}
		$scope.pagehide = function() {
			$scope.page.show = false;
			$scope.page.hide = true;
		}
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Order/order_list',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token")
			}
		}).success(function(data) {
			console.log(data)
			$rootScope.login(data)
			if(!data["list"]) {
				$scope.page.rongcuo = true
			} else {
				$scope.page.rongcuo = false
				$scope.orderList = data["list"]
			}
			//1.已取消   2.待付款  3.已支付   4.申请售后  5.售后已解决
			//iscomment    0.没有评论    1.已经评论    2.已追加评论
			$scope.toOrderinfo = function(id) {
				$state.go("main.orderInfor", {
					Id: id
				})
			}
			$timeout(function() {
				for(var i = 0; i < $(".pay_status").length; i++) {
					if($(".status_name")[i].innerHTML == "已解决") {
						$(".topay").eq(i).html("删除订单").css({
							"color": "#666",
							"border-color": "#666"
						})
						$(".delpay").eq(i).hide()
					}
					if($(".status_name")[i].innerHTML == "待付款") {
						$(".topay").eq(i).html("去支付")
						$(".delpay").eq(i).html("取消订单")
					}
					if($(".status_name")[i].innerHTML == "申请售后") {
						$(".topay").eq(i).html("申请退款")
						$(".delpay").eq(i).hide()
					}
					if($(".status_name")[i].innerHTML == "待评价") {
						$(".topay").eq(i).html("去评价")
						$(".delpay").eq(i).html("取消订单")
					}
					if($(".status_name")[i].innerHTML == "可追加评论") {
						$(".topay").eq(i).html("查看评论")
						$(".delpay").eq(i).html("追加评论")
					}
					if($(".status_name")[i].innerHTML == "售后") {
						$(".topay").eq(i).html("查看售后")
						$(".delpay").eq(i).hide()
					}
					if($(".status_name")[i].innerHTML == "已评价") {
						$(".topay").eq(i).html("查看评论")
						$(".delpay").eq(i).hide()
					}
				}
				$rootScope.page.goshow = false
				$(".topay").click(function() {
					var orderNum = $(this).attr("orderNum")
					if($(this).html() == "去支付") {
						$state.go("main.payment", {
							str: orderNum,
							num: 3
						})
					}
					if($(this).html() == "去评价") {
						$state.go("main.routcomment", {
							Id: orderNum,
							types: 1
						})
					}
					if($(this).html() == "查看评论") {
						$state.go("main.routecommentlist")
					}
					if($(this).html() == "申请退款") {
						$state.go("main.after_service", {
							id: orderNum
						})
					}
				})
				$(".delpay").click(function() {
					if($(this).html() == "取消订单") {
						$(".order_del").show()
						var orderNum = $(this).attr("orderNum")
						var that = $(this)
						$(".yes").click(function() {
							$http({
								method: 'post',
								url: '' + $rootScope.Location + 'Order/cancel',
								headers: {
									'Content-Type': 'application/x-www-form-urlencoded'
								},
								data: {
									user_Id: localStorage.getItem("user_ID"),
									token: localStorage.getItem("token"),
									order_Id: orderNum
								}
							}).success(function(data) {
								$(".order_del").hide()
								if(data["status"] == 1) {
									that.parent().parent().parent().remove()
									$(".addressdialog").show();
									$(".addressdialog").html(data["message"]);
									$(".addressdialog").fadeOut(1200);
								} else {
									$(".addressdialog").show();
									$(".addressdialog").html(data["message"]);
									$(".addressdialog").fadeOut(1200);
								}
							})
						})
						$(".no").click(function() {
							$(".order_del").hide()
						})
					}
				})
			}, 50)
		})
	}])
	//待付款
app.controller("wait_pay", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$rootScope.page.goshow = true
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Order/unpaid',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token")
		}
	}).success(function(data) {
		$rootScope.login(data)
		$scope.toOrderinfo = function(id) {
			$state.go("main.orderInfor", {
				Id: id
			})
		}
		$rootScope.page.goshow = false
		if(!data["list"] || data["list"].length == 0) {
			$scope.page.rongcuo = true
		} else {
			$scope.orderList = data["list"]
			$scope.page.rongcuo = false
		}
		$scope.topay = function(orderNum) {
				$state.go("main.payment", {
					str: orderNum,
					num: 3
				})
			}
			//		$(".topay").click(function() {
			//			alert(11)
			//			if($(this).html() == "去支付") {		
			//				var orderNum = $(this).attr("orderNum")
			//				
			//			}
			//		})
	})
}])
app.controller("wait_comment", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	scrollTo(0, 0);
	$rootScope.page.goshow = true
	$scope.page.show = true;
	$scope.page.hide = false;
	$scope.pageshow = function() {
		$scope.page.show = true;
		$scope.page.hide = false;
	}
	$scope.pagehide = function() {
		$scope.page.show = false;
		$scope.page.hide = true;
	}
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Order/uniscomment',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token")
		}
	}).success(function(data) {
		console.log(data)
		$rootScope.login(data)
		$scope.toOrderinfo = function(id) {
			$state.go("main.orderInfor", {
				Id: id
			})
		}
		$rootScope.page.goshow = false
		if(!data["list"]["uniscpmment"] || data["list"]["uniscpmment"].length == 0) {
			$scope.page.rongcuo = true
		} else {
			$scope.page.rongcuo = false
			$scope.comment = data["list"]["uniscpmment"]
		}
		if(!data["list"]["iscomment"] || data["list"]["iscomment"].length == 0) {
			$scope.page.rongcuo2 = true
		} else {
			$scope.page.rongcuo2 = false
			$scope.comment2 = data["list"]["iscomment"]
		}
		$scope.goagainComment = function(Id, id) {
			$state.go("main.routcomment", {
				Id: Id,
				id: id,
				types: 2,
				type: 1
			})
		}
		$scope.goComment = function(Id, id) {
			$state.go("main.routcomment", {
				Id: Id,
				id: id,
				types: 1,
				type: 1
			})
		}
	})
}])
app.controller("after_sales", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	scrollTo(0, 0);
	$rootScope.page.goshow = true
	$scope.page.show = true;
	$scope.page.hide = false;
	$scope.pageshow = function() {
		$scope.page.show = true;
		$scope.page.hide = false;
	}
	$scope.pagehide = function() {
		$scope.page.show = false;
		$scope.page.hide = true;
	}
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Order/after_sale',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token")
		}
	}).success(function(data) {
		console.log(data)
		$rootScope.login(data)
		$scope.toOrderinfo = function(id) {
			$state.go("main.orderInfor", {
				Id: id
			})
		}	
		setTimeout(function(){
				$(".topay").click(function(){
				var orderNum = $(this).attr("orderNum")
				if($(this).html() == "申请退款") {
					$state.go("main.after_service",{
						id:orderNum
					})
				}
			})
			},100)
		$rootScope.page.goshow = false
		if(!data["list"]["left"] || data["list"]["left"].length == 0) {
			$scope.page.rongcuo = true
		} else {
			$scope.sale = data["list"]["left"]
			$scope.page.rongcuo = false	
		}
		if(!data["list"]["right"] || data["list"]["right"].length == 0) {
			$scope.page.rongcuo2 = true
		} else {
			$scope.saleright = data["list"]["right"]
			$scope.page.rongcuo2 = false
		}
	})
}])

//订单详情
app.controller("orderInfor", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Order/detail',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			order_Id: $stateParams.Id
		}
	}).success(function(data) {
		console.log(data)
		$rootScope.login(data)
		$scope.list = data["list"]
		if(data["list"]["status_name"] == "已解决") {
			$(".topay").html("取消订单").css({
				"color": "#666",
				"border-color": "#666"
			})
			$(".delpay").hide()
		}
		if(data["list"]["status_name"] == "待付款") {
			$(".topay").html("去支付")
			$(".delpay").html("取消订单").css({
				"color": "#666",
				"border-color": "#666"
			})
		}
		if(data["list"]["status_name"] == "申请售后") {
			$(".topay").html("申请退款")
			$(".delpay").hide()
		}
		if(data["list"]["status_name"] == "待评价") {
			$(".topay").html("去评价")
			$(".delpay").html("取消订单").css({
				"color": "#666",
				"border-color": "#666"
			})
		}
		if(data["list"]["status_name"] == "可追加评论") {
			$(".topay").html("查看评论")
			$(".delpay").hide()
		}
		if(data["list"]["status_name"] == "售后") {
			$(".topay").html("申请退款")
			$(".delpay").hide()
		}
		if(data["list"]["status_name"] == "已评价") {
			$(".topay").html("查看评论")
			$(".delpay").hide()
		}
		$rootScope.page.goshow = false
		$(".topay").click(function() {
			var orderNum = $(this).attr("orderNum")
			if($(this).html() == "去支付") {				
				$state.go("main.payment", {
					str: orderNum,
					num: 3
				})
			}
			if($(this).html() == "查看评论") {
				$state.go("main.routecommentlist")
			}
			if($(this).html() == "申请退款") {
				$state.go("main.after_service",{
					id:orderNum
				})
			}
		})
		$(".delpay").click(function() {
			if($(this).html() == "取消订单") {
				$(".order_del").show()
				var orderNum = $(this).attr("orderNum")
				$(".yes").click(function() {
					$http({
						method: 'post',
						url: '' + $rootScope.Location + 'Order/cancel',
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						data: {
							user_Id: localStorage.getItem("user_ID"),
							token: localStorage.getItem("token"),
							order_Id: orderNum
						}
					}).success(function(data) {
						$(".order_del").hide()
						if(data["status"] == 1) {
							$(".addressdialog").show();
							$(".addressdialog").html(data["message"]);
							$(".addressdialog").fadeOut(1200);
							setTimeout(function() {
								$state.go("main.myOrder")
							}, 1200)
						} else {
							$(".addressdialog").show();
							$(".addressdialog").html(data["message"]);
							$(".addressdialog").fadeOut(1200);
						}
					})
				})
				$(".no").click(function() {
					$(".order_del").hide()
				})
			}
		})
	})
}])

app.controller("after_service", ["$scope", "$rootScope", "$stateParams", "$state", "$http", function($scope, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Order/show_sale',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			order_Id: $stateParams.id
		}
	}).success(function(data) {
		console.log(data)
		$rootScope.login(data)
		$scope.list = data["list"]
	})
	$scope.submit = function() {
		var content = $("#textarea").val()
		$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Order/sub_sale',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
				order_Id: $stateParams.id,
				content:content
			}
		}).success(function(data) {
			console.log(data)
			if(data["status"]==1){
				$(".addressdialog").show();
				$(".addressdialog").html(data["message"]);
				$(".addressdialog").fadeOut(1200);
				setTimeout(function(){
					$state.go("main.after_sales")
				},1200)
			}else{
				$(".addressdialog").show();
				$(".addressdialog").html(data["message"]);
				$(".addressdialog").fadeOut(1200);
			}
		})
	}
}])